package com.orange.core.config.wx;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.impl.WxMaRedissonConfigImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RedissonClient;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Slf4j
@RequiredArgsConstructor
@Configuration
@EnableConfigurationProperties(WxProperty.class)
public class WxMaConfig {

    private final WxProperty property;
    private final RedissonClient redissonClient;

    @Bean
    public WxMaService wxMaService() {
        WxMaRedissonConfigImpl config = new WxMaRedissonConfigImpl(redissonClient, "wx");
        config.setAppid(property.getAppid());
        config.setSecret(property.getSecret());

        WxMaService maService = new WxMaServiceImpl();
        maService.setWxMaConfig(config);
        return maService;
    }
}
